package com.rcp.server;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/AssignedTable")
public class AssignedTable extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public AssignedTable() {
        super();
        // TODO Auto-generated constructor stub
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String url = "jdbc:mysql://cs3.calstatela.edu:3306/cs437group01";
        String username = "cs437group01";
        String password = "VHj#dj!v";
        boolean[] assigned = new boolean[30]; 
        
        for(int i = 0; i < 30; i++){
        	assigned[i] = false;
        }
        
        Connection c;
		try {
			c = DriverManager
			    .getConnection( url, username, password );
			
//getting beef menu			
			Statement stmt = c.createStatement();
	        ResultSet rs = stmt.executeQuery("SELECT TableID FROM  `Tables` WHERE EmployeeID =2");
	        
	        while( rs.next() )
            {	            		
        		assigned[rs.getInt("TableID")] = true;
            }
	        
	        getServletContext().setAttribute( "assigned", assigned );
	        request.getRequestDispatcher("/WEB-INF/server/AssignedView.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
